/*
*@description: 历史记录
*@author: 作者
*@date: 2023-03-06 09:44:08
*@email: 邮箱
*/

<!--  -->
<template>
    <div class=''>

        <el-card shadow="always" :body-style="{ padding: '20px' }">
            <div slot="header">
                <span>历史记录</span>
            </div>
            <div>
                <el-table border :data="tableData" stripe style="width: 100%">
                    <el-table-column prop="name" label="名称">
                    </el-table-column>
                    <el-table-column prop="startTime" label="开始时间">
                    </el-table-column>
                    <el-table-column prop="endTime" label="结束时间">
                    </el-table-column>
                    <el-table-column prop="createName" label="操作人">
                    </el-table-column>
                </el-table>
                <el-row :gutter="20" style="margin-top:15px;">
                    <el-col :span="24" :offset="0" style="text-align:right;">
                        <el-pagination style="mar" :page-size="pageSize" :current-page="pageNum" @current-change="changePage" background layout="total, prev, pager, next" :total="total">
                        </el-pagination>
                    </el-col>
                </el-row>


            </div>
        </el-card>

    </div>
</template>

<script>
    import axios from 'axios'
    export default {
        components: {},
        data() {
            return {
                tableData: [{}], //表格数据
                list: [],
                total: 0,
                pageNum: 1,
                pageSize: 10
            };
        },
        computed: {},
        created() {
            if (this.list.length >= 88) return
            axios.get('/getHistory/page').then((res) => {
                console.log(res.data.list, 'res')
                this.list = res.data.list
                let arr = this.changePageAndSize(res.data.list, 1, 10)
                this.total = arr.total
                this.tableData = arr.list
            })
        },
        methods: {
            changePage(page) {
                this.pageNum = page
                let arr = this.changePageAndSize(this.list, page, 10)
                this.tableData = arr.list
            },
            // 根据参数pageNum与pageSize实现分页功能
            changePageAndSize(selfArr, pageNum, pageSize) {
                let arr = JSON.parse(JSON.stringify(selfArr))
                var totalPage = []
                var pageAllNum = Math.ceil(selfArr.length / pageSize) || 1
                for (let i = 0; i < pageAllNum; i++) {
                    totalPage[i] = selfArr.slice(pageSize * i, pageSize * (i + 1))
                }
                selfArr = totalPage[pageNum - 1]
                return {
                    list: selfArr,
                    total: arr.length,
                    code: '200',
                    message: 'success'
                }
            }
        },
    }
</script>
<style scoped>
</style>